﻿using Abp.Authorization;
using Abp.Localization;
using Abp.MultiTenancy;

namespace Sunlit.House.Authorization
{
    public class HouseAuthorizationProvider : AuthorizationProvider
    {
        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            var pages = context.GetPermissionOrNull(PermissionNames.Pages) ?? context.CreatePermission(PermissionNames.Pages, L("PermissionManager"));

            pages.CreateChildPermission(PermissionNames.Pages_Users, L("Users"));
            pages.CreateChildPermission(PermissionNames.Pages_Users_Activation, L("UsersActivation"));
            pages.CreateChildPermission(PermissionNames.Pages_Roles, L("Roles"));
            pages.CreateChildPermission(PermissionNames.Pages_Tenants, L("Tenants"), multiTenancySides: MultiTenancySides.Host);

            var system = pages.CreateChildPermission(PermissionNames.Pages_System, L("SystemSettings"));
            system.CreateChildPermission(PermissionNames.Pages_System_Region, L("RegionManager"));

            var groupBuy = pages.CreateChildPermission(PermissionNames.Pages_GroupBuy,L("GroupBuyManager"));
            groupBuy.CreateChildPermission(PermissionNames.Pages_GroupBuy_OpenGroup, L("OpenGroup"));
            groupBuy.CreateChildPermission(PermissionNames.Pages_GroupBuy_JoinGroup, L("JoinGroup"));

            var newsCategory = pages.CreateChildPermission(PermissionNames.Pages_NewsCategory, L("NewsCategory"));
            newsCategory.CreateChildPermission(PermissionNames.Pages_NewsCategory_Create, L("CreatingNewsCategory"));
            newsCategory.CreateChildPermission(PermissionNames.Pages_NewsCategory_Edit, L("EditingNewsCategory"));
            newsCategory.CreateChildPermission(PermissionNames.Pages_NewsCategory_Delete, L("DeletingNewsCategory"));

            var news = pages.CreateChildPermission(PermissionNames.Pages_News, L("News"));
            news.CreateChildPermission(PermissionNames.Pages_News_Create, L("CreatingNews"));
            news.CreateChildPermission(PermissionNames.Pages_News_Edit, L("EditingNews"));
            news.CreateChildPermission(PermissionNames.Pages_News_Delete, L("DeletingNews"));

            var floor = pages.CreateChildPermission(PermissionNames.Pages_Floor, L("Floor"));
            floor.CreateChildPermission(PermissionNames.Pages_Floor_Create, L("CreatingFloor"));
            floor.CreateChildPermission(PermissionNames.Pages_Floor_Edit, L("EditingFloor"));
            floor.CreateChildPermission(PermissionNames.Pages_Floor_Delete, L("DeletingFloor"));

            var village = pages.CreateChildPermission(PermissionNames.Pages_Village, L("Village"));
            village.CreateChildPermission(PermissionNames.Pages_Village_Create, L("CreatingVillage"));
            village.CreateChildPermission(PermissionNames.Pages_Village_Edit, L("EditingVillage"));
            village.CreateChildPermission(PermissionNames.Pages_Village_Delete, L("DeletingVillage"));

            var secondHand = pages.CreateChildPermission(PermissionNames.Pages_SecondHand, L("SecondHand"));
            secondHand.CreateChildPermission(PermissionNames.Pages_SecondHand_Create, L("CreatingSecondHand"));
            secondHand.CreateChildPermission(PermissionNames.Pages_SecondHand_Edit, L("EditingSecondHand"));
            secondHand.CreateChildPermission(PermissionNames.Pages_SecondHand_Delete, L("DeletingSecondHand"));
        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, HouseConsts.LocalizationSourceName);
        }
    }
}
